package com.hyx.api.controller.applet_shop;

import com.hyx.api.config.ApiPrefixRestController;
import com.hyx.api.domain.User;
import com.hyx.api.domain.bo.*;
import com.hyx.api.service.IAppCommonService;
import com.hyx.api.service.IAppRecoverService;
import com.hyx.api.service.IAppShopService;
import com.hyx.api.service.pc_admin.IInquiryOrderService;
import com.hyx.api.utils.base.MobileBaseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RequiredArgsConstructor
@ApiPrefixRestController
@RequestMapping("/appShopApi/order")
public class AppShopOrderController extends BaseController {

    private final IAppShopService appShopService;

    private final IAppRecoverService recoverService;

    private final IInquiryOrderService inquiryOrderService;

    private final MobileBaseService mobileBaseService;

    private final IAppCommonService appCommonService;

    /**
     * 新增询价订单 --- 对接
     */
    @PostMapping("/insertInquiryOrder")
    public AjaxResult insertInquiryOrder(@Validated @RequestBody InquiryOrderBo bo) {
        return toAjax(appShopService.insertInquiryOrder(bo));
    }

    /**
     * 获取关于询价订单的报价信息 --- 对接
     * 根据询价订单id获取询价详情
     */
    @GetMapping("/queryInquiryOrderDetail")
    public AjaxResult queryOfferOrderByInquiryId(@RequestParam("inquiryOrderId") Long inquiryOrderId) {
        return inquiryOrderService.queryInquiryOrderDetailById(inquiryOrderId, null);
    }

    /**
     * 询价订单绑定报价订单_中标 --- 对接
     *
     * @param inquiryOrderId
     * @param offerOrderId
     * @return
     */
    @GetMapping("/inquiryBindOfferOrder")
    public AjaxResult inquiryBindOfferOrder(@RequestParam("inquiryOrderId") Long inquiryOrderId, @RequestParam("offerOrderId") Long offerOrderId) {
        return appShopService.inquiryBindOfferOrder(inquiryOrderId, offerOrderId);
    }

    /**
     * 回收订单状态更新_当回收商付款后通过该接口将回收订单状态改为待发货，当门店将设备发货后填入快递单等信息将状态改为待收货，同时支持门店取消订单 --- 对接
     *
     * @param bo
     * @return
     */
    @PostMapping("/recycleOrderStaUpdate")
    public AjaxResult recycleOrderStaUpdate(@RequestBody RecOrderStaUpdateBo bo) {
        return appShopService.recycleOrderStaUpdate(bo);
    }

    /**
     * 获取待处理的订单_以门店为维度   已对接
     *
     * @return
     */
    @GetMapping("/queryShopNoHandleOrderList")
    public AjaxResult queryShopNoHandleOrderList() {
        return appShopService.queryShopNoHandleOrderList();
    }

    /**
     * 获取门店待处理订单详情 --- 对接
     *
     * @param recycleOrderId
     * @return
     */
    @GetMapping("/queryShopNoHandleOrderDetail")
    public AjaxResult queryShopNoHandleOrderDetail(@RequestParam("recycleOrderId") Long recycleOrderId) {
        return appShopService.queryShopNoHandleOrderDetail(recycleOrderId);
    }

    /**
     * 获取当前门店所有询价中订单列表  已对接
     * <p>
     * 只获取当前店员的询价订单 并且在十分钟以内
     *
     * @return
     */
    @GetMapping("/queryInquiringList")
    public AjaxResult queryInquiringList() {
        return appShopService.queryInquiringList();
    }

    /**
     * 当前个人所有询价订单，店长门店所有人  --- 对接
     */
    @GetMapping("/inquiry/all/list")
    public AjaxResult queryInquiryAllList(@RequestParam(required = false) Integer status) {
        return appShopService.queryInquiryAllList(status);
    }

    /**
     * 获取公司关联的回收商
     *
     * @param keyword
     * @return
     */
    @GetMapping("/queryShopBindRecycleBusList")
    public AjaxResult queryShopBindRecycleBusList(@RequestParam(required = false) String keyword) {
        return appShopService.queryShopBindRecycleBusList(keyword);
    }

    /**
     * 获取回收订单列表    ---- 已对接
     *
     * @param req
     * @return
     */
    @PostMapping("/queryRecycleOrderList")
    public TableDataInfo queryRecycleOrderList(@RequestBody ShopRecOrderQueBo req) {
        startPage();
        return getDataTable(appCommonService.queryRecycleOrderList(req));
    }

    /**
     * 修改退货订单状态  --- 对接
     *
     * @param refundOrderId
     * @param status
     * @return
     */
    @GetMapping("/updateRefundOrderStatus")
    public AjaxResult updateRefundOrderStatus(@RequestParam Long refundOrderId, @RequestParam Integer status) {
        return appShopService.updateRefundOrderStatus(refundOrderId, status);
    }

    /**
     * 获取退货订单列表  --- 已对接
     *
     * @param req
     * @return
     */
    @PostMapping("/queryRefundOrderList")
    public TableDataInfo queryRefundOrderList(@RequestBody ShopRefOrderQueBo req) {
        startPage();
        return getDataTable(appShopService.queryRefundOrderList(req));
    }

    /**
     * 审核追差订单
     *
     * @param req
     * @return
     */
    @PostMapping("/auditSpreadOrder")
    public AjaxResult auditSpreadOrder(@RequestBody SpreadOrderBo req) {
        return appShopService.auditSpreadOrder(req);
    }


    /**
     * 获取追差订单列表 --- 已对接
     *
     * @param req
     * @return
     */
    @PostMapping("/querySpreadOrderList")
    public TableDataInfo querySpreadOrderList(@RequestBody ShopSpreadQueBo req) {
        startPage();
        return getDataTable(appShopService.querySpreadOrderList(req));
    }

    /**
     * 获取门店发货数量记录  --- 已对接
     *
     * @return
     */
    @GetMapping("/queryShopSendCountInfo")
    public AjaxResult queryShopSendCountInfo() {
        return appShopService.queryShopSendCountInfo();
    }

    /**
     * 获取门店统计数据
     *
     * @param req
     * @return
     */
    @PostMapping("/queryShopStatistics")
    public AjaxResult queryShopStatistics(@RequestBody @Valid ShopStatisticsBo req) {
        return appShopService.queryShopStatistics(req);
    }

    /**
     * 生成加价审批订单
     *
     * @param bo
     * @return
     */
    @PostMapping("/addSpreadOrder")
    public AjaxResult addSpreadOrder(@RequestBody SpreadOrderBo bo) {
        return recoverService.addSpreadOrder(bo);
    }

    /**
     * 修改加价审批订单
     *
     * @param bo
     * @return
     */
    @PostMapping("/updateSpreadOrder")
    public AjaxResult updateSpreadOrder(@RequestBody SpreadOrderBo bo) {
        return recoverService.updateSpreadOrder(bo);
    }

    /**
     * 获取当前用户的业绩
     *
     * @return
     */
    @GetMapping("/queryEnterprise")
    public AjaxResult queryEnterprise() {
        return appShopService.queryEnterprise();
    }

    /**
     * 获取询价订单的消息
     *
     * @param inquiryOrderId
     * @return
     */
    @GetMapping("/queryMsgDialogueList")
    public AjaxResult queryMsgDialogueList(@RequestParam Long inquiryOrderId) {
        return appShopService.queryMsgDialogueList(inquiryOrderId);
    }

}
